#include <utils.h>
#include <common.h>


int
get_sha1sum(const char *path, char *digest)
{
    FILE *fp = fopen(path, "rb");
    if (fp == NULL) {
        return -1;
    }
    char buf[8192];
    size_t len;
    gsize size = 20;
    GChecksum *cks = g_checksum_new(G_CHECKSUM_SHA1);
    while ((len = fread(buf, 1, sizeof (buf), fp))) {
        g_checksum_update(cks, (guint8 *) buf, len);
    }
    g_checksum_get_digest(cks, (guint8 *) digest, &size);
    g_checksum_free(cks);
    return 0;
}
